/*
 * ElementTest.cpp
 *
 *  Created on: 06/mar/2013
 *      Author: lordmzn
 */

#include <gtest/gtest.h>
#include "MOLEM/Element.h"
#include <cmath>

namespace MOLEMTests {

class ElementTest : public ::testing::Test {

public:
	ElementTest() : val(13.0) {
	}
	double val;
};

TEST_F(ElementTest, ConstructorsTest) {
	// construct element, get, set and get z vals
	MOLEM::Element a(1,1);
	ASSERT_EQ(MOLEM::ELEMENT_Z_DEFAULT_VALUE, a.getZvalue()) << "init of z value failed";
	a.setZvalue(val);
	ASSERT_EQ(val, a.getZvalue()) << "set/get of z value failed";
	MOLEM::Element b(a);
	ASSERT_EQ(a.getZvalue(), b.getZvalue()) << "copy constructor doesn't copy z";
}

TEST_F(ElementTest, ConnectionTestV1) {
	// construct 5 element, connect one of it and check conn
	MOLEM::Element w(1,0);
	MOLEM::Element n(0,1);
	MOLEM::Element c(1,1);
	MOLEM::Element e(1,2);
	MOLEM::Element s(2,1);
	ASSERT_EQ(true, c.connect(w, n, e, s)) << "connect fail";
	ASSERT_TRUE(c.isConnected()) << "isConnected fail";
}

TEST_F(ElementTest, CartesianDistance) {
	// construct 5 element, connect one of it and check conn
	MOLEM::Element nw(0,0);
	MOLEM::Element n(0,1);
	MOLEM::Element c(1,1);
	MOLEM::Element e(1,2);
	ASSERT_DOUBLE_EQ(sqrt(2), c.getCartesianDistance(nw)) << "distance c-nw fail";
	ASSERT_DOUBLE_EQ(sqrt(1), n.getCartesianDistance(nw)) << "distance n-nw fail";
	ASSERT_DOUBLE_EQ(sqrt(5), e.getCartesianDistance(nw)) << "distance e-nw fail";
}
} /* namespace MOLEMTests */


